package cz.muni.fi.hauntedhouses.service.impl;

import cz.muni.fi.hauntedhouses.dao.HouseDAO;
import cz.muni.fi.hauntedhouses.service.HouseService;
import cz.muni.fi.hauntedhouses.to.HouseTO;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author Jan Volmut, 324836
 */
@Service
@Transactional
public class HouseServiceImpl implements HouseService {

    @Autowired
    private HouseDAO houseDAO;
    
    @Override
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public void create(HouseTO house) {
        this.houseDAO.create(house);
    }

    @Override
    public HouseTO get(Long id) {
        return this.houseDAO.get(id);
    }

    @Override
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public void update(HouseTO house) {
        this.houseDAO.update(house);
    }

    @Override
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public void delete(HouseTO house) {
        this.houseDAO.delete(house);
    }

    @Override
    public List<HouseTO> findAll() {
        return this.houseDAO.findAll();
    }

    @Override
    public List<HouseTO> findByName(String name) {
        return this.houseDAO.findByName(name);
    }
}
